package logic

import (
	"context"
	"houseRpc/models"

	"houseRpc/house"
	"houseRpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookingListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookingListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookingListLogic {
	return &BookingListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookingListLogic) BookingList(in *house.BookingListRequest) (*house.BookingListResponse, error) {
	// todo: add your logic here and delete this line

	var bs []models.Booking
	var listBooking []*house.BookingList

	models.DB.Where("user_id=?", in.UserId).Find(&bs)

	for _, b := range bs {
		list := house.BookingList{
			UserId:  int64(b.UserId),
			HouseId: int64(b.HouseId),
			BkDate:  b.BkDate,
			Status:  int64(b.Status),
		}
		listBooking = append(listBooking, &list)
	}

	return &house.BookingListResponse{
		List: listBooking,
	}, nil
}
